//
//  HotBrandTableViewCell.m
//  19_CarHomeWork
//
//  Created by dllo on 16/8/9.
//  Copyright © 2016年 DM.C. All rights reserved.
//

#import "HotBrandTableViewCell.h"
#import "HotCollectionViewCell.h"
#import "HotList.h"
#import "HotBrand.h"
#import "HotResult.h"
#import "UIImageView+DownloadImage.h"
@class CustomHotLayout;
@interface HotBrandTableViewCell ()<UICollectionViewDelegate, UICollectionViewDataSource>
@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *layout;
@property (weak, nonatomic) IBOutlet UICollectionView *hotCollectionView;
@property (nonatomic, strong) NSMutableArray *hotListArray;
@property (nonatomic, strong) HotBrand *brand;
@end
@implementation HotBrandTableViewCell
- (void)layoutSubviews {
    [super layoutSubviews];
//    _hotListArray = [NSMutableArray array];
    // item size
    CGFloat width = CGRectGetWidth([UIScreen mainScreen].bounds);
    self.layout.itemSize = CGSizeMake((width - 90) / 5.0 , ((width - 120) / 5.0) * 1.618);
    // item之间最小间距(横向)
    self.layout.minimumInteritemSpacing = 10;
    // 纵向最小间距
    self.layout.minimumLineSpacing = 10;
    // 滑动方向
    //    self.flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    // 分区边缘距离
    self.layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    // 设置分区的头部和尾部视图大小.
    self.layout.headerReferenceSize = CGSizeMake(0, 0);
    
    self.layout.footerReferenceSize = CGSizeMake(0, 0);
    
    
    self.hotCollectionView.delegate = self;
    self.hotCollectionView.dataSource = self;
//    [self hotBrandHandleData];
    if (_list) {
        [_hotCollectionView reloadData];
    }

}
- (void)hotBrandHandleData {
    NSString *hotBrandJSON = [[NSBundle mainBundle] pathForResource:@"HotBrand" ofType:@"json"];
    NSData *hotBrandData = [NSData dataWithContentsOfFile:hotBrandJSON];
    NSError *error = nil;
    NSDictionary *hotBrandDic = [NSJSONSerialization JSONObjectWithData:hotBrandData options:NSJSONReadingMutableContainers error:&error];
    // hotBrand
    _brand = [HotBrand modelWithDic:hotBrandDic];
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _list.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    HotCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HotCollectionReuse" forIndexPath:indexPath];

       [cell.hotCarImageView asyncDownloadImageWithURL:_list[indexPath.row].img completionHandler:^(NSData *data, UIImage *image) {
    }];
    cell.hotCarName.text = _list[indexPath.row].name;
    
    return cell;
}

- (void)awakeFromNib {
    [super awakeFromNib];
   
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
